﻿<BadHabit_Factory_Controls:GenericPanel x:Class="BadHabit.Factory.Controls.TeamPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
    xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls"        
    xmlns:BadHabit_Factory_Converters="clr-namespace:BadHabit.Factory.Converters"  
    
    xmlns:BadHabit_WPFTools_Converters="clr-namespace:BadHabit.WPFTools.Converters;assembly=BadHabit.WPFTools"                                    
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools"       
    xmlns:Microsoft_Toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"    
    xmlns:Factory_Core="clr-namespace:BadHabit.Factory;assembly=FactoryCore"    
                                        
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
                                        
    xmlns:props="clr-namespace:BadHabit.Factory.Properties"

    Loaded="GenericPanel_Loaded"
                                        
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    Background="Transparent">

    <!-- The commands for this window -->
    <UserControl.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Delete" Executed="Delete_Executed" />        
        <CommandBinding Command="ApplicationCommands.Save" CanExecute="Save_CanExecute" Executed="Save_Executed"/>
    </UserControl.CommandBindings>
        
    <UserControl.Resources>

        <!-- Converters -->
        <BadHabit_Factory_Converters:UnitNameConverter x:Key="UnitNameConverter" />        
    

        <!-- Data Providers -->        
        <ObjectDataProvider x:Key="ClientContactsList" ObjectInstance="{x:Null}" />

        <!-- Item template for the Add Member menu -->
        <DataTemplate x:Key="UnitMenuItemTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0"
                       DataContext="{Binding Type, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:TeamRoles}}"
                       Style="{StaticResource RoleTypeImage}" Margin="0,0,2,0" Width="16" Height="16" Stretch="Uniform"/>
                <TextBlock Grid.Column="1" Text="{Binding UnitDescription}"/>
            </Grid>
        </DataTemplate>
        
        <!-- Item template for the Role list view -->
        <DataTemplate x:Key="RoleItemTemplate">
            
                <Grid Margin="2,2,10,2" HorizontalAlignment="Stretch" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>                        
                    </Grid.ColumnDefinitions>
                
                    <BadHabit_WPFTools:ComboBox                                
                            x:Name="memberComboBox"                                 
                            Grid.Column="0"                                                    
                            BadHabit_WPFTools:RoleChecker.RequiredEnableRole="SCRUM_MASTER"                                                                                                           
                            Width="300"                                
                            SelectedItemTemplate="{StaticResource TeamMemberTemplate}"
                            SelectedValue="{Binding ContactId}"        
                            SelectedValuePath="MemberId"
                            Loaded="memberComboBox_Loaded"
                            SelectionChanged="memberComboBox_SelectionChanged">
                    <BadHabit_WPFTools:ComboBox.Style>
                        <Style BasedOn="{StaticResource TeamComboBox}" TargetType="BadHabit_WPFTools:ComboBox">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ClientContactRole}" Value="True">
                                    <Setter Property="BadHabit_WPFTools:ComboBox.ItemsSource" Value="{Binding Source={StaticResource ActiveTeamMemberList}}"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ClientContactRole}" Value="False">
                                    <Setter Property="BadHabit_WPFTools:ComboBox.ItemsSource" Value="{Binding Source={StaticResource ClientContactsList}}"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </BadHabit_WPFTools:ComboBox.Style>



                </BadHabit_WPFTools:ComboBox>
                    
                <!-- Remove member button -->
                <Button     Cursor="Hand"
                            Grid.Column="1"                                        
                            BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                            Command="ApplicationCommands.Delete"
                            VerticalAlignment="Center"
                            Style="{StaticResource TransparentButton}">
                    <Image                                                                                                                    
                            VerticalAlignment="Top"                        
                            Source="/Images/ToolBar/remove.png"
                            Width="16" Height="16" Stretch="Uniform" Margin="0,0,5,0"
                            ToolTip="{x:Static props:Resources.Click_here_to_remove_this_team_member}">                        
                    </Image>
                </Button>
            </Grid>
            
     
        </DataTemplate>
        
    </UserControl.Resources>

    <Grid x:Name="ContentPanel" VerticalAlignment="Stretch">
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <DockPanel Grid.Row="0">
            <ToolBar DockPanel.Dock="Left" ToolBarTray.IsLocked="True" Height="60" >

                <Menu>                
                <MenuItem   
                    BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                    Header="{x:Static props:Resources.Add_Member}"                                        
                    MenuItem.Click="addMember_Click"                    
                    Style="{StaticResource ToolBarMenuItem}"
                    ItemTemplate="{StaticResource UnitMenuItemTemplate}"
                    ItemsSource="{Binding Source={StaticResource UnitList}}">
                    <MenuItem.Icon>
                        <Image Source="/Images/ToolBar/teamMember.png" Stretch="Uniform" Width="32" Height="32"/>
                    </MenuItem.Icon>
                </MenuItem>
                
                <MenuItem   
                    BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER" 
                    Style="{StaticResource ToolBarMenuItem}"
                    x:Name="editRoleButton"                   
                    Header="{x:Static props:Resources.Edit_Roles}"                                        
                    Click="editRoleButton_Click">                    
                    <MenuItem.Icon>
                        <Image Source="/Images/ToolBar/EditRoles.png" Stretch="Uniform" Width="32" Height="32"/>
                    </MenuItem.Icon>
                </MenuItem>
                
            </Menu>            
            
            
            
        </ToolBar>
            <Button
                        x:Name="commitButton"
                        DockPanel.Dock="Right"
                        Style="{StaticResource CommitButton}"
                        Command="ApplicationCommands.Save"
                        HorizontalAlignment="Right" 
                        Margin="5" />
        </DockPanel>
        

            <Grid  Grid.Row="1" VerticalAlignment="Stretch" Margin="3">
                <Grid.Resources>
                    <CollectionViewSource x:Key="ProjectRoleList" Source="{Binding ProjectRole}">
                        <CollectionViewSource.GroupDescriptions>
                            <PropertyGroupDescription PropertyName="UnitName"/>
                        </CollectionViewSource.GroupDescriptions>
                    </CollectionViewSource>

                </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
                <GroupBox Grid.Column="0" Header="{x:Static props:Resources.Team_MMembers}">
                    <ListBox                                          
                    x:Name="teamListView"
                    Background="Transparent"
                    BorderThickness="0"
                    
                    HorizontalContentAlignment="Stretch"                                                            
                    HorizontalAlignment="Stretch"
                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                    ItemsSource="{Binding Source={StaticResource ProjectRoleList}}"
                    ItemContainerStyle="{StaticResource NoSelectionListBoxItem}"
                    ItemTemplate="{StaticResource RoleItemTemplate}">
                        <ListBox.GroupStyle>
                            <GroupStyle>
                                <GroupStyle.ContainerStyle>
                                    <Style TargetType="{x:Type GroupItem}">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type GroupItem}">
                                                    <Expander
                                                    DataContext="{Binding Path=Name, Converter={StaticResource UnitNameConverter}}"
                                                    Header="{Binding UnitDescription}"
                                                    IsExpanded="True">
                                                        <Expander.HeaderTemplate>
                                                            <DataTemplate>
                                                                <TextBlock Text="{Binding .}" Foreground="{StaticResource DarkTextBrush}" FontSize="13"/>
                                                            </DataTemplate>
                                                        </Expander.HeaderTemplate>
                                                        <ItemsPresenter />
                                                    </Expander>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </GroupStyle.ContainerStyle>
                            </GroupStyle>
                        </ListBox.GroupStyle>

                    </ListBox>
                </GroupBox>
                <GroupBox Grid.Column="1" Header="{x:Static props:Resources.Project_Access_Level}" DataContext="{Binding Project[0]}">
                <Border Background="#FAFAFA" BorderBrush="#DDDDDD" BorderThickness="1" Padding="3" VerticalAlignment="Top">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Image Grid.Column="0" Source="/Images/Icons/prjAccessMode.png" Width="32" Height="32" Stretch="Uniform" />
                        
                        <StackPanel Grid.Column="1">
                            <RadioButton GroupName="accessLevel"
                                         Style="{StaticResource FormRadioButton}"
                                         IsChecked="{Binding AccessMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=0}"
                                         >
                                <TextBlock>
                                    <Bold><TextBlock Text="{x:Static props:Resources.ALL_SEE_ALL_WORK}"/></Bold><LineBreak/>
                                    <TextBlock Text="{x:Static props:Resources.ALL_SEE_ALL_WORK_tooltip}"/><LineBreak/>                                    
                                </TextBlock>                                
                            </RadioButton>
                            <RadioButton GroupName="accessLevel"
                                         Style="{StaticResource FormRadioButton}"
                                         IsChecked="{Binding AccessMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=1}"
                                         >
                                <TextBlock>
                                    <Bold><TextBlock Text="{x:Static props:Resources.ALL_SEE_TEAM_WORK}"/></Bold><LineBreak/>
                                    <TextBlock Text="{x:Static props:Resources.ALL_SEE_TEAM_WORK_tooltip}"/>
                                </TextBlock>                                
                            </RadioButton>
                        </StackPanel>
                        
                    </Grid>
                </Border>
                
                </GroupBox>
            </Grid>

     
            
        
   
        


    </Grid>

</BadHabit_Factory_Controls:GenericPanel>
